gtkplacesview: bail out if operation cancelled
authorCarlos Soriano <csoriano@gnome.org>
Fri, 21 Aug 2015 17:57:07 +0000 (19:57 +0200)
committerCarlos Soriano <csoriano@gnome.org>
Fri, 21 Aug 2015 17:58:52 +0000 (19:58 +0200)
When an operation is cancelled it's never safe to access
the object itself or the private struct, since it could be
called (and probably is) during finalize.

In case the operation is cancelled, just bail out to fix
the crashes.

gtk/gtkplacesview.c

index 60ee5f69f72dee0409cb0b6fe68a2734f620c980..f71e26c742c511bd3ed98202cebe1a54a1e88317 100644 (file)
@@ -1145,21 +1145,11 @@ server_mount_ready_cb (GObject      *source_file,
   GError *error;
   GFile *location;
 
-  view = GTK_PLACES_VIEW (user_data);
-  priv = gtk_places_view_get_instance_private (view);
   location = G_FILE (source_file);
   should_show = TRUE;
   error = NULL;
 
-  priv->should_pulse_entry = FALSE;
-  set_busy_cursor (view, FALSE);
-
   g_file_mount_enclosing_volume_finish (location, res, &error);
-  /* Restore from Cancel to Connect */
-  gtk_button_set_label (GTK_BUTTON (priv->connect_button), _("Con_nect"));
-  gtk_widget_set_sensitive (priv->address_entry, TRUE);
-  priv->connecting_to_server = FALSE;
-
   if (error)
     {
       should_show = FALSE;
@@ -1176,14 +1166,30 @@ server_mount_ready_cb (GObject      *source_file,
                (error->code != G_IO_ERROR_CANCELLED &&
                 error->code != G_IO_ERROR_FAILED_HANDLED))
         {
+          view = GTK_PLACES_VIEW (user_data);
           /* if it wasn't cancelled show a dialog */
           emit_show_error_message (view, _("Unable to access location"), error->message);
           should_show = FALSE;
         }
-
+      else
+        {
+          /* it was cancelled, so probably it was called during finalize, bail out. */
+          g_clear_error (&error);
+          return;
+        }
       g_clear_error (&error);
     }
 
+  view = GTK_PLACES_VIEW (user_data);
+  priv = gtk_places_view_get_instance_private (view);
+  priv->should_pulse_entry = FALSE;
+  set_busy_cursor (view, FALSE);
+
+  /* Restore from Cancel to Connect */
+  gtk_button_set_label (GTK_BUTTON (priv->connect_button), _("Con_nect"));
+  gtk_widget_set_sensitive (priv->address_entry, TRUE);
+  priv->connecting_to_server = FALSE;
+
   if (should_show)
     {
       server_list_add_server (view, location);
@@ -1234,14 +1240,10 @@ volume_mount_ready_cb (GObject      *source_volume,
   GVolume *volume;
   GError *error;
 
-  view = GTK_PLACES_VIEW (user_data);
-  priv = gtk_places_view_get_instance_private (view);
   volume = G_VOLUME (source_volume);
   should_show = TRUE;
   error = NULL;
 
-  set_busy_cursor (view, FALSE);
-
   g_volume_mount_finish (volume, res, &error);
 
   if (error)
@@ -1264,10 +1266,20 @@ volume_mount_ready_cb (GObject      *source_volume,
           emit_show_error_message (GTK_PLACES_VIEW (user_data), _("Unable to access location"), error->message);
           should_show = FALSE;
         }
+      else
+        {
+          /* it was cancelled, so probably it was called during finalize, bail out. */
+          g_clear_error (&error);
+          return;
+        }
 
       g_clear_error (&error);
     }
 
+  view = GTK_PLACES_VIEW (user_data);
+  priv = gtk_places_view_get_instance_private (view);
+  set_busy_cursor (view, FALSE);
+
   if (should_show)
     {
       GMount *mount;